package com.fp.m7.shared.services;

import java.util.List;

import com.fp.m7.shared.ValidationResult;
import com.fp.m7.shared.dto.AccountDto;
import com.fp.m7.shared.dto.UserDto;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public interface AccountServiceAsync {

    void checkUsernameAvailability(String username, AsyncCallback<Boolean> callback);

    void checkNicknameAvailability(String nickname, AsyncCallback<Boolean> callback);

    void newAccount(String username, String password, String nickname, String captchaText,
            AsyncCallback<ValidationResult> callback);

    void deleteAccount(AsyncCallback<Boolean> callback);

    void changeNickname(String newNickname, AsyncCallback<Boolean> callback);

    void updateStatus(String newStatus, AsyncCallback<Boolean> callback);

    void updateDescription(String newDescription, AsyncCallback<Boolean> callback);

    void updateStatusAndDescription(String newStatus, String newDescription, AsyncCallback<Boolean> callback);

    void updateAvatarUrl(String newAvatarUrl, AsyncCallback<Boolean> callback);

    void getDetails(String nickname, AsyncCallback<AccountDto> callback);

    void getAuthenticatedAccount(AsyncCallback<AccountDto> callback);

    void changePassword(String oldPassword, String newPassword, AsyncCallback<ValidationResult> callback);

    void getRandomUsers(int maxCount, AsyncCallback<List<UserDto>> callback);

    /**
     * Utility class to get the RPC Async interface from client-side code
     */
    public static final class Util {
        private static AccountServiceAsync instance;

        public static AccountServiceAsync getInstance() {
            if (instance == null) {
                instance = (AccountServiceAsync) GWT.create(AccountService.class);
            }
            return instance;
        }

        private Util() {
            // Utility class should not be instantiated
        }
    }
}
